package com.ovopark.organize.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ovopark.organize.server.mapper.FranchiseesApprovalTemplateGroupMapper;
import com.ovopark.organize.server.model.entity.FranchiseesApprovalTemplateGroup;
import com.ovopark.organize.server.service.FranchiseesApprovalTemplateGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author wxb
 * @Title: FranchiseesApprovelServiceImpl
 * @Description: 加盟商立项模板
 * @date 2024/4/11 15:51
 **/
@Service
@Slf4j
public class FranchiseesApprovalTemplateGroupServiceImpl extends ServiceImpl<FranchiseesApprovalTemplateGroupMapper, FranchiseesApprovalTemplateGroup> implements FranchiseesApprovalTemplateGroupService {

    /** 
     * @description: 获取企业模板 企业配置的系统模板
     * @param: [groupId, templateId]
     * @return: com.ovopark.organize.server.model.entity.FranchiseesApprovalTemplateGroup
     * @author wxb
     * @date: 2024/6/5 11:00
     */ 
    @Override
    public FranchiseesApprovalTemplateGroup getGroupTemplate(Integer groupId, Integer templateId) {
        LambdaQueryWrapper<FranchiseesApprovalTemplateGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FranchiseesApprovalTemplateGroup::getGroupId, groupId);
        queryWrapper.eq(FranchiseesApprovalTemplateGroup::getTemplateId, templateId);
        queryWrapper.eq(FranchiseesApprovalTemplateGroup::getIsDeleted, 0);
        queryWrapper.last("limit 1");
        return this.baseMapper.selectOne(queryWrapper);
    }

    /**
     * @description: 关闭模板
     * @param: [groupId]
     * @return: void
     * @author wxb
     * @date: 2024/6/2 20:48
     */
    @Override
    public void closeTemplate(Integer groupId) {
        if (groupId != null) {
            FranchiseesApprovalTemplateGroup templateGroup = new FranchiseesApprovalTemplateGroup();
            templateGroup.setGroupId(groupId);
            templateGroup.setIsOpen(0);
            LambdaQueryWrapper<FranchiseesApprovalTemplateGroup> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(FranchiseesApprovalTemplateGroup::getGroupId, groupId);
            queryWrapper.eq(FranchiseesApprovalTemplateGroup::getIsOpen, 1);
            this.baseMapper.update(templateGroup, queryWrapper);
        }
    }

    /**
     * @description: 保存企业模板关系
     * @param: [templateGroup]
     * @return: void
     * @author wxb
     * @date: 2024/6/18 16:26
     */
    @Override
    public void saveTemplateGroup(FranchiseesApprovalTemplateGroup templateGroup) {
        if (templateGroup != null) {
            this.baseMapper.insert(templateGroup);
        }
    }
}
